<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .search {
            position: relative;
            width: 400px;
            height: 100px;
        }
        
        .con {
            display: none;
            position: absolute;
            top: 10px;
            left: 10px;
            width: 200px;
            height: 30px;
            background-color: #fff;
            border: 1px solid rgba(0, 0, 0, .2);
            font-size: 18px;
        }
        
        .con::before {
            content: '';
            width: 0;
            height: 0;
            position: absolute;
            top: 31px;
            left: 10px;
            border: 5px solid #333;
            border-style: solid dashed dashed;
            border-color: #fff transparent transparent;
        }
        
        .jd {
            position: absolute;
            top: 50px;
            left: 10px;
            width: 200px;
            height: 10px;
            margin-top: 10px;
            background-color: #fff;
        }
    </style>
</head>

<body>
    <div class="search">
        <div class="con"></div>
        <input type="text" placeholder="请输入快递单号" class="jd">
    </div>
    <script>
        var con = document.querySelector(".con");
        var txt = document.querySelector(".jd");
        //keypress和keydown事件出发时，文字还没有落入文本框，所以得用keyup
        //keyup事件触发时，文字已经落入文本框
        txt.addEventListener('keyup', function() {
                if (this.value == '') {
                    con.style.display = 'none';
                } else {
                    con.style.display = 'block';
                    con.innerHTML = this.value;
                }
            })
            //文本框失去焦点，上面的消失
        txt.addEventListener('blur', function() {
                con.style.display = 'none';
            })
            //文库获得焦点，上面的显示
        txt.addEventListener('focus', function() {
            //如果里面内容为空则不显示
            if (this.value != '') {
                con.style.display = 'block';
            }
        })
    </script>
</body>

</html>